package com.inspur.ourhis_afterend.Tools;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeConvert {
    private static String pattern = "yyyy-MM-dd HH:mm:ss";

    // 日期转化为字符
    public static String dateToString(Date date) {
        return new SimpleDateFormat(pattern).format(date);
    }

    // 字符转化为日期
    public static Date stringToDate(String str) throws IllegalAccessException {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        try {
            return sdf.parse(str);
        } catch (ParseException e) {
            throw new IllegalAccessException("传入日期格式类型不正确");
        }
    }
}
